/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.rest.AnonymousGetMapping;
import me.zhengjie.annotation.rest.AnonymousPostMapping;
import me.zhengjie.base.AjaxResult;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.service.DictDetailService;
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author Zheng Jie
 * @date 2018-12-26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/index")
@Api(tags = "通用方法")
public class IndexController extends CommonController {

//    private final VerifyService verificationCodeService;

    private final DictDetailService dictDetailService;

    @AnonymousGetMapping(value = "/version")
    @ApiOperation("版本升级检测")
    public AjaxResult version(){

        List<DictDetail> list = dictDetailService.queryAllBydictId(6L);

        Map<String, Object> version = new HashMap<String, Object>();
        for (DictDetail item : list){
            version.put(item.getLabel(),item.getValue());
        }
//        Map<String, Object> version = new HashMap<String, Object>() {{
//            put("adrVersion", "1.1.1");
//            put("adrTitle","升级标题");
//            put("adrTips","升级描述语");
//            put("adrUrl","http://www.baidu.com/");
//            put("xcxUrl","");
//        }};
        return AjaxResult.success(version);
    }

    /**
     * 上传图片
     * @param upfile
     * @return
     */
    @AnonymousPostMapping("/uploadImg")
    public AjaxResult uploadImg(@RequestParam MultipartFile upfile) {
        return _uploadFile(upfile,"img");
    }

    /**
     * 上传文件
     * @param upfile
     * @return
     */
    @AnonymousPostMapping("/uploadFile")
    public AjaxResult uploadFile(@RequestParam MultipartFile upfile) {
        return _uploadFile(upfile,"file");
    }

}
